<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
  import DialogEditor from '@/components/DialogEditor'
  import dialogMixins from '@/utils/commonDialogMixins'
  export default {
    mixins: [dialogMixins],
    components: {DialogEditor},
    data () {
      return {
        dataFormConfig:{
          orderDetailId: {
            disabled: true,

            label: '订单编号',
            type: 'list',
            list: [],
            placeholder: '请输入订单',
            filterable: true,
           // selectCallback: this.orderSelectCallback
          },
          productId: {
            disabled: true,

            label: '产品',
            type: 'list',
       //     selectCallback: this.productSelectCallback,
            filterable: true,
            list: [],
            placeholder: '请选择产品',
       //     isNeedAdd: true,
       //     addNewItemFunc: this.addNewProduct
          },
          clientId: {
            disabled: true,
            type: 'list',
            list: [],
            label: '客户名',
            filterable: true,
            placeholder: '请输入客户名',
      //      isNeedAdd: true,
      //      addNewItemFunc: this.addNewClientInfo
          },
          realSaleNumber: {
            disabled: true,
            label: '销售数量',
            type: 'number',
            max: 10000000,
            default: 0,
            selectCallback: this.numberChanged
          },
          productPrice: {
            label: '单价',
            type: 'number',
            max: 1000,
            default: 0,
            selectCallback: this.numberChanged
          },
          totalSaleAmount:{
            label: '销售总额',
            disabled: true
          },

          remark: {
            label: '备注',
            inputType: 'textarea',
            placeholder: '请输入备注'
          },
          status: {
            label: '状态',
            type: 'switch',
            activeValue: 1,
            inactiveValue: 0,
            default: 1
          }
        }
      }
    },
    methods: {
      numberChanged() {
        const realSaleNumber = this.R.propOr(0, 'realSaleNumber', this.dataForm)
        const productPrice = this.R.propOr(0, 'productPrice', this.dataForm)

        this.dataForm.totalSaleAmount = realSaleNumber * productPrice
      },
      init (id) {
        this.dataForm.id = id || 0
        this.initDeepOrderDetailList()
        this.initProductInfoList()
        this.initClientInfoList()
        this.$refs.dialog.initDialog({
          dataForm: this.dataForm,
          config: this.dataFormConfig,
          stepsConfig: this.stepsConfig,
          dataRule: this.getNeedDataRule('orderDetailId','clientId', 'realSaleNumber', 'productId', 'productPrice', 'status'),
          initApi: 'deepApi/deepStatementAccountInfo',
          saveApi: 'deepApi/saveDeepStatementAccount',
          updateApi: 'deepApi/updateDeepStatementAccount',
          objectName: 'deepStatementAccount'
        })
      }
    }
  }
</script>
